﻿using OOAD_PROJEKAT;
using DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Xceed.Wpf.Toolkit;

namespace Main_application
{
    /// <summary>
    /// Interaction logic for EFS_Radnik.xaml
    /// </summary>
    public partial class EFS_Radnik : Window
    {
        Window1 pom;
        Zaposlenik pom1;
        List<Steta> stete;
        IntegerUpDown broji;
        public EFS_Radnik(Window1 logi, Zaposlenik k)
        {
            InitializeComponent();
            pom = logi;
            broji = new IntegerUpDown();
            broji.Minimum = 0;
            broji.Value = 0;
            broji.Margin = new Thickness(0, 24, 0, 23);
            broji.Height = 20;
            mreza.Children.Add(broji);
            Grid.SetColumn(broji, 1);
            pom1 = k;
            stete = new List<Steta>();
            jed.BorderBrush = SystemColors.ControlDarkBrush;
            dva.BorderBrush = SystemColors.ControlDarkBrush;
            tri.BorderBrush = SystemColors.ControlDarkBrush;
            DAL.DAL.StetaDAO st = new DAL.DAL.StetaDAO();
            stete = st.getAll();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (Steta x in stete)
            {
                ListBoxItem it = new ListBoxItem();
                it.Content = x.Id.ToString();
                lista.Items.Add(it);
            }
        }

        private void lista_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            foreach (Steta x in stete)
            {
                if (lista.SelectedValue.ToString() == "System.Windows.Controls.ListBoxItem: " + x.Id.ToString())
                {
                    tekst.Text = x.OpisStete;
                    datum.Text = x.DatumStete.ToShortDateString();
                    cijena.Text = x.Isplata.ToString();
                    break;
                }
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(cijena.Text))
            {
                naplata.IsEnabled = false;
            }
            else
            {
                naplata.IsEnabled = true;
                foreach (Steta x in stete)
                {
                    if (lista.SelectedValue.ToString() == "System.Windows.Controls.ListBoxItem: " + x.Id.ToString())
                    {
                        DAL.DAL.StetaDAO st = new DAL.DAL.StetaDAO();
                        x.Validirana = true;
                        x.Isplata = Convert.ToDouble(broji.Value);
                        st.update(x);
                        global::System.Windows.MessageBox.Show("Šteta je uspješno naplaćena", "Šteta naplaćena", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    }
                }
            }
        }

        private void lista_GotFocus(object sender, RoutedEventArgs e)
        {
            
        }
    }
}
